package com.HuiShou.mapper;

import java.math.BigDecimal;
import java.util.List;
import com.HuiShou.domain.UserPointsAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 积分账户Mapper接口
 * 
 * @author lyz
 * @date 2025-03-21
 */
public interface UserPointsAccountMapper extends BaseMapper<UserPointsAccount>
{
    /**
     * 通过用户ID锁定账户记录（FOR UPDATE）
     * @param userId 用户ID
     * @return 用户积分账户实体
     */
    @Select("SELECT * FROM user_points_account WHERE user_id = #{userId} FOR UPDATE")
    UserPointsAccount selectForUpdate(@Param("userId") Long userId);
    /**
     * 查询积分账户
     * 
     * @param userId 积分账户主键
     * @return 积分账户
     */
    public UserPointsAccount selectUserPointsAccountByUserId(Long userId);

    /**
     * 查询积分账户列表
     * 
     * @param userPointsAccount 积分账户
     * @return 积分账户集合
     */
    public List<UserPointsAccount> selectUserPointsAccountList(UserPointsAccount userPointsAccount);

    /**
     * 新增积分账户
     * 
     * @param userPointsAccount 积分账户
     * @return 结果
     */
    public int insertUserPointsAccount(UserPointsAccount userPointsAccount);

    /**
     * 修改积分账户
     * 
     * @param userPointsAccount 积分账户
     * @return 结果
     */
    public int updateUserPointsAccount(UserPointsAccount userPointsAccount);

    /**
     * 删除积分账户
     * 
     * @param userId 积分账户主键
     * @return 结果
     */
    public int deleteUserPointsAccountByUserId(Long userId);

    /**
     * 批量删除积分账户
     * 
     * @param userIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteUserPointsAccountByUserIds(Long[] userIds);

    @Update("update user_points_account set balance = #{balance} where user_id = #{userId}")
    void updateByIdD(@Param("balance") BigDecimal balance, @Param("userId") Long userId);
}
